package com.health.mapp.impl;

import com.health.db.model.RegisterOrder;
import com.health.db.service.order.IRegisterOrderService;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.bean.DeleteOrderReq;
import com.health.mapp.bean.DeleteOrderResp;
import com.health.mapp.bean.Header;
import com.health.mapp.utils.Constant;
import com.health.mapp.utils.DateUtils;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/** 
 *  订单删除接口    
 * 注：已完成 已结束可操作
 * @author HiRoad
 *
 */
public class DeleteOrderImpl implements ActionInterface {
	
	//service import
	private IRegisterOrderService registerOrderService ;
	private IUserLISTService userLISTService  ;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		DeleteOrderReq req = (DeleteOrderReq) reqBean; 
		DeleteOrderResp _resp = new DeleteOrderResp();
		Long orderId = req.getOrderId();
		Long userId = req.getUserId();
		//校验入参
		if (orderId==0) {
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ORDERID);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ORDERID_NOTE);
			return _resp;
		}
		
		if (orderId==0) {
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_USERID);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_USERID_NOTE);
			return _resp;
		}		
			//RegisterOrder orderInfo = new RegisterOrder();
			
			//入参
		//	orderInfo.setUpdateUserid(userId);
			//orderInfo.setUserDeleteFlag(Constant.CONSTANTS_ORDER_USERDELETE_FLAG);
			//orderInfo.setRegisterid(orderId);
			
			RegisterOrder  currRegisterOrder =registerOrderService.selectSimpleSingleByOrderId(orderId);
			
			//判断订单状态
			if (currRegisterOrder==null) {
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3001);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3001_NOTE);
				return _resp;
			}
			int runStatusId=currRegisterOrder.getRunstatusid();
			//判断类型
			if (runStatusId!=Constant.CONSTANTS_ORDER_RUNSTATUS_ID_5
					&&runStatusId!=Constant.CONSTANTS_ORDER_RUNSTATUS_ID_6) {
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3004);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3004_NOTE);
				return _resp;
			}
			//入参
			currRegisterOrder.setUpdateUserid(userId);
			currRegisterOrder.setUserDeleteFlag(Constant.CONSTANTS_ORDER_USERDELETE_FLAG);
			currRegisterOrder.setRegisterid(orderId);
			
			currRegisterOrder.setUpdateDate(DateUtils.now());
			
			int executNum= registerOrderService.updateOrder4Delete(currRegisterOrder);
			
			//确认插入正确
			if (executNum!=1) {
				_resp.setErrorCode(ResultCode.OPERATION_OTHER_ERROR);
				_resp.setErrorMsg(ResultCode.OPERATION_OTHER_ERROR_NOTE);
				return _resp;
			}
		//}
		
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
 
		return _resp;
	}
	
	public IRegisterOrderService getRegisterOrderService() {
		return registerOrderService;
	}


	public void setRegisterOrderService(IRegisterOrderService registerOrderService) {
		this.registerOrderService = registerOrderService;
	}


	public IUserLISTService getUserLISTService() {
		return userLISTService;
	}


	public void setUserLISTService(IUserLISTService userLISTService) {
		this.userLISTService = userLISTService;
	}
	

}
